<template>
   <div>
     <div class="little-title">患者详情 :</div>

     <el-form :model="register" size="small"  label-width="68px">
       <el-form-item label="病历号" >
         <el-input v-model="register.registId"  readonly/>
       </el-form-item>

       <el-form-item label="患者姓名" >
         <el-input v-model="register.name" readonly/>
       </el-form-item>
     </el-form>

     <div class="little-title">检查项目详情 :</div>
     <el-form :model="inspectApply"  size="small"  label-width="68px">

       <el-form-item label="项目名称" >
         <el-input v-model="inspectApply.name" readonly/>
       </el-form-item>
       <el-form-item label="项目名称" >
         <el-input v-model="inspectApply.price" readonly/>
       </el-form-item>
       <el-form-item label="检查结果" >
           <el-input type="textarea" v-model="inspectApply.result" />
         </el-form-item>



       <el-form-item label="影响结果"   v-if="type =='edit'">
         <el-upload
           class="upload-demo"
           action="/dev-api/upload/upload"
           :on-preview="handlePreview"
           :on-remove="handleRemove"
           :on-success="handleSuccess"
           :before-remove="beforeRemove"
           multiple
           :limit="10"
           :on-exceed="handleExceed"
           :file-list="fileList">
           <el-button size="small" type="primary">点击上传</el-button>
           <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div>
         </el-upload>
       </el-form-item>

       <el-form-item label="影像结果"   v-if="type =='show'">
         <img :src="'/dev-api/upload/download?uploadId='+upload.uploadId" v-for="upload in  uploads"  width="100px" height="100px" @click="open('/dev-api/upload/download?uploadId='+upload.uploadId)"/>
       </el-form-item>



           <el-form-item>
             <el-button type="primary" icon="el-icon-search" size="mini" @click="saveInspectResult" v-if="type =='edit'" >保存</el-button>
             <el-button type="primary" icon="el-icon-search" size="mini" @click="close" v-else-if="type =='show'" >关闭</el-button>
           </el-form-item>
     </el-form>



   </div>

</template>

<script>
import {querInspectItemDetail,saveInspectResult} from '@/api/medical_technology/medical_technology'
export default {
  name: "inspect_apply_detail",
  props:[
    "itemId","visible",'type'
  ],
  data(){
    return{
      register:{},
      inspectApply:{},
      fileList: [],
      uploadIds:[],
    }
  },
  methods:{
    open(url){
      window.open(url);
    },
    close(){
      this.$emit("update:visible",false);
    },
    saveInspectResult(){
      let ids = this.uploadIds.join(",");
      let result = this.inspectApply.result;
      let itemId = this.inspectApply.itemId;

      saveInspectResult( {  ids:ids,result:result,itemId:itemId  } ).then(res=>{
          if(res){
            this.$message("检验结果处理成功");
            this.$emit("update:visible",false);
            this.$emit("close");
          }
      })

    },
    handleRemove(file, fileList) {
      console.log(file, fileList);
    },
    handlePreview(file) {
      console.log(file);
    },
    handleExceed(files, fileList) {
      this.$message.warning(`当前限制选择 3 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`);
    },
    beforeRemove(file, fileList) {
      return this.$confirm(`确定移除 ${ file.name }？`);
    },
    handleSuccess(response, file, fileList){
      let res = response.data
      if(res.success){
        this.uploadIds.push(res.id);
      }
    },
    querInspectItemDetail(){

      querInspectItemDetail(this.itemId).then(res=>{
        this.register =  res.register;
        this.inspectApply = res.inspectApply;
        this.uploads = res.uploads;
      })

    }
  },
  created() {
      this.querInspectItemDetail();
  }
}
</script>

<style scoped>
    .little-title{
        background-color: #d3dce6;
      font-weight: 900;
      font-size: 18px;
      padding: 5px 20px;
    }
</style>
